package com.test.convert;

import java.util.Map;

import com.opensymphony.xwork2.conversion.impl.DefaultTypeConverter;
import com.test.bean.Point;

public class PointConvert extends DefaultTypeConverter
{

	@Override
	public Object convertValue(Map<String, Object> context, Object value,
			Class toType)
	{
		System.out.println("convertValue ...");
		if( Point.class ==  toType)
		{
			//str --> Point
			
			String[] str = (String[])value;
			
			String[] convertValue = str[0].split(",");
			
			Integer x = Integer.valueOf(convertValue[0]);
			Integer y = Integer.valueOf(convertValue[1]);
			
			Point point = new Point();
			point.setX(x);
			point.setY(y);
			
			return point;
		}
		else if (String.class == toType)
		{
			//Point --> str
			Point point = (Point)value;
			
			String result = "X:" + point.getX() + " | Y:" + point.getY();
			
			return result;
		}
		else
		{
			return null;
		}
	}

}
